<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script th:src="@{/webjars/jquery/3.0.0/jquery.js}"></script>
    <link th:href="@{/css/ydui.css}" rel="stylesheet">
    <script th:src="@{/js/ydui.flexible.js}"></script>
</head>
<body>
<section class="g-flexview">

    <header class="m-navbar">
        <a href="#nogo" class="navbar-item" onclick="finish();return false;"><i class="back-ico"></i>返回</a>
        <div class="navbar-center"><span class="navbar-title">我发布的</span></div>
    </header>

    <section class="g-scrollview" id="J_List_all">
        <div id="J_ListContent_all" class="m-list list-theme4"></div>
    </section>
</section>
<script id="J_ListHtml" type="text/html">
    {{each products as product}}
    <a href="#nogo" onclick="open_detail({{product.id}});return false;" class="list-item">
        <div class="list-img">
            <img src="http://static.ydcss.com/uploads/ydui/goods_default.jpg" data-url="{{product.showImg}}">
        </div>
        <div class="list-mes">
            <h3 class="list-title">{{product.title}}</h3>
            <div class="list-mes-item">
                <div>
                    <span class="list-price"><em>¥</em>{{product.price}}</span>
                    {{if product.buyPrice != null && product.buyPrice != 0}}
                        <span class="list-del-price">¥{{product.buyPrice}}</span>
                    {{/if}}
                    {{if "insale" == product.status}}
                        <span class="badge badge-radius badge-warning spec_span" style="margin-top: .6rem;float: right;margin-right: 4rem;">未售出</span>
                        <span class="btn btn-warning" style="float: right;margin-bottom: 0.2rem;" onclick="delete_product({{product.id}},event);return false;">删除商品</span>
                    {{/if}}
                    {{if "saled" == product.status}}
                        <span class="badge badge-radius badge-warning" style="margin-top: .6rem;float: right;margin-right: 4rem;">已售</span>
                    {{/if}}
                    {{if "deleted" == product.status}}
                        <span class="badge badge-radius badge-warning" style="margin-top: .6rem;float: right;margin-right: 4rem;">已删除</span>
                    {{/if}}
                </div>
            </div>
        </div>
    </a>
    {{/each}}
</script>
<script src="http://static.ydcss.com/libs/arttemplate/template.js"></script>
<script th:src="@{/js/ydui.js}"></script>
<script th:inline="javascript">
    !function () {
        // 根据实际情况自定义获取数据方法
        var user_id = [[${user_id}]];
        var page = 1;
        var pageSize = 10;
        var loadAllMore = function (callback) {
            $.ajax({
                url: '/app/get_publish_datas/',
                type: 'POST',
                dataType: 'json',
                data: {
                    "page": page,
                    "pagesize": pageSize,
                    "user_id": user_id,
                },
                success: function (ret) {
                    callback(ret);
                }
            });
        };
        $('#J_List_all').infiniteScroll({
            binder: '#J_List_all',
            pageSize: pageSize,
            initLoad: true,
            loadingHtml: '<img src="http://static.ydcss.com/uploads/ydui/loading/loading10.svg"/>',
            loadListFn: function () {
                var def = $.Deferred();

                loadAllMore(function (listArr) {

                    var html = template('J_ListHtml', {products: listArr, user_id: user_id});
                    $('#J_ListContent_all').append(html).find('img').lazyLoad({binder: '#J_List_all'});
                    def.resolve(listArr);
                    $(".m-navbar").show();
                });
                ++page;
                return def.promise();
            }
        });
    }();

    function open_detail(order_id){
        window.publish.openDetail(order_id);
    }

    function finish(){
        window.publish.finishActivity();
    }

    function reload_this() {
        window.publish.reloadWeb();
    }


    function delete_product(product_id,event) {
        event.stopPropagation();
        var url = "/app/delete_product_by_id/";
        var post_param = {"product_id":product_id};
        YDUI.dialog.confirm('删除操作无法撤回！谨慎操作',  '警告！',  function () {
            /* 确定后调用 */
            $.post(url,post_param,function (res) {
                if(res == 'success'){
                    reload_this();
                }else{
                    YDUI.dialog.alert('删除失败！');
                }
            });
        });
    }
</script>
</body>
</html>
